/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package captchabuster;

import com.googlecode.fannj.Fann;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author alexnewski
 */
public class Train {

    protected String folder;
    protected List<String> classes;

    /**
     * Get the value of folder
     *
     * @return the value of folder
     */
    public String getFolder() {
        return folder;
    }

    /**
     * Set the value of folder
     *
     * @param folder new value of folder
     */
    public void setFolder(String folder) {
        this.folder = folder;
    }

    public List<String> getClasses() {
        return classes;
    }

    public void setClasses(List<String> classes) {
        this.classes = classes;
    }

    public Train(List<String> classes) {
        this.classes = classes;
    }

    public void run(String nettype, String traindir) {
        long total_training_time = 0l;
        //String letter = "a_";
        for (String letter : classes) {
            long start, end, total;
            start = System.currentTimeMillis();


            String trainpath = traindir + "/" + letter + ".data";
            File data = new File(trainpath);
            String networkpath = data.getAbsolutePath().substring(0, data.getAbsolutePath().length() - trainpath.length()) + "networks/" + letter + nettype + ".net";
            if (data.canRead()) {
                FannTrainer ft = new FannTrainer(18400, 123, 1, data.getAbsolutePath());
                Fann fann = ft.getFann();
                fann.save(networkpath);
                fann.close();
            }


            end = System.currentTimeMillis();
            total = end - start;
            total_training_time += total;

            System.out.println("char: " + letter + " training time: " + total + "ms (" + (double) total / (60 * 1000) + "mins)");
        }

        System.out.println("Total training time: " + total_training_time + "ms (" + (double) total_training_time / (60 * 1000) + "mins)");
    }
}
